import { Controller, Get, Post, Body, Patch, Param, Delete, UseGuards } from '@nestjs/common';
import { CategoryService } from './category.service';
import { Category } from '../../entities/category.entity';
import { Public } from '../../common/decorators/public.decorator';
import { ApiTags, ApiOperation, ApiResponse, ApiBody, ApiParam } from '@nestjs/swagger';

@ApiTags('分类管理')
@Controller('api/categories')
export class CategoryController {
  constructor(private readonly categoryService: CategoryService) {}

  // 获取所有分类（公开接口）
  @Public()
  @Get()
  @ApiOperation({
    summary: '获取所有分类',
    description: '获取系统中所有的文章分类',
  })
  @ApiResponse({
    status: 200,
    description: '获取成功',
    type: [Category],
  })
  findAll() {
    return this.categoryService.findAll();
  }

  // 获取单个分类详情（公开接口）
  @Public()
  @Get(':id')
  @ApiOperation({
    summary: '获取单个分类',
    description: '根据分类ID获取分类详细信息',
  })
  @ApiParam({
    name: 'id',
    description: '分类ID',
    example: '1',
  })
  @ApiResponse({
    status: 200,
    description: '获取成功',
    type: Category,
  })
  @ApiResponse({
    status: 404,
    description: '分类不存在',
  })
  findOne(@Param('id') id: number) {
    return this.categoryService.findOne(id);
  }

}
